 <?
	$group = $dsfm_common->get_all("common_group");
	$tpl->assign("group", $group);

	$all_assessment = $dsfm_common->get_all("assessment", "year=".$_SESSION['year']." ORDER BY sub ASC");
	$tpl->assign("all_assessment", $all_assessment);

	if(isset($id)){
		$assessment = $dsfm_common->get("assessment", "id = ".$id);

		if($assessment['type'] == 1){

			if($_SESSION['user']['level_name'] != "officer"){
				$assessment['p5'] = set_text_point($assessment['p4'], $assessment['p5']);
				$assessment['p4'] = set_text_point($assessment['p3'], $assessment['p4']);
				$assessment['p3'] = set_text_point($assessment['p2'], $assessment['p3']);
				$assessment['p2'] = set_text_point($assessment['p1'], $assessment['p2']);
				$assessment['p1'] = set_text_point(0, $assessment['p1']);
			}

			$standard = $dsfm_common->get_all("assessment_standard", "aid = ".$id);
			$tpl->assign("standard", $standard);

		}else{

			$common = $dsfm_common->get_all("common", "gid = ". $assessment['gid']. " and year = ".$_SESSION['year']);
			$tpl->assign("common", $common);

			if($assessment['unit'] == 1){
				$check[0] = "checked";
			}else{
				$check[1] = "checked";
			}

			if($assessment['common1'] != 0){
				$sql = "SELECT * FROM common WHERE id = ".$assessment['common1'];
				$common1 = $db->query($sql);
				$data = new Data($common1);
				$tpl->assign("common1", $data->fetch_unique());

				$sql = "SELECT * FROM common WHERE id = ".$assessment['common2'];
				$common2 = $db->query($sql);
				$data = new Data($common2);
				$tpl->assign("common2", $data->fetch_unique());
			}
		}

		if($_SESSION['user']['level_name'] != "officer"){
			$assessment['principle'] = nl2br($assessment['principle']);
			$assessment['related'] = nl2br($assessment['related']);
		}

		if($_SESSION['user']['level_name'] != "assessor"){
			$assessment['project'] = nl2br($assessment['project']);
		}

		$tpl->assign("assessment", $assessment);

		$upload = $dsfm_common->get_all("assessment_file","aid=".$id." ORDER BY id ASC");
		$tpl->assign("upload", $upload);

		if($assessment['target'] <= $assessment['result']){
			$tpl->assign("pass", "images/pass.gif");
		}else{
			$tpl->assign("pass", "images/fail.gif");
		}
	}

	$tpl->assign("id", $id);

	$tpl->draw("assessment");

	function set_text_point($p1, $p2){
		if($p2 == 0){
			return 0;
		}elseif($p2 - $p1 == 1) {
			return $p2;
		}else{
			return ($p1+1)." - ".$p2;
		}
	}
?>